package com.xingdata.jjxc.base;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import android.view.GestureDetector;
import android.view.KeyEvent;
import android.widget.Toast;

import com.ab.activity.AbActivity;
import com.xingdata.jjxc.R;
import com.xingdata.jjxc.enty.UserEntity;
import com.xingdata.jjxc.views.Widget;

public abstract class ComBaseActivity extends AbActivity {

	/**
	 * 
	 */
	protected UserEntity user;
	protected String[] info;

	protected GestureDetector mGestureDetector;
	protected ProgressDialog progressDialog;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	/**
	 * 控件都在此方法中声明, 比如:
	 * 
	 * Button b = (Button) findViewById(R.id.button);
	 * 
	 */
	protected abstract void initViews();

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			finish();
		}
		Widget.startActivityAnim(this, R.anim.avty_slide_in_from_left,
				R.anim.avty_slide_out_from_right);
		return super.onKeyDown(keyCode, event);
	}

	/**
	 * 判断网络连接状态
	 * 
	 * @param context
	 * @return 状态
	 */
	protected boolean isNetworkConnected() {

		ConnectivityManager cwjManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

		cwjManager.getActiveNetworkInfo();
		boolean netSataus = true;
		if (cwjManager.getActiveNetworkInfo() == null) {

			netSataus = false;
		}
		return netSataus;
	}



	
	/**
	 * 显示 ProgressDialog
	 */
	protected ProgressDialog showProgressDialog(String title, String message) {
		if (progressDialog != null && progressDialog.isShowing()) {
			progressDialog.dismiss();
		}
		progressDialog = ProgressDialog.show(this, title, message);
		progressDialog.setCancelable(false);
		progressDialog
				.setOnCancelListener(new DialogInterface.OnCancelListener() {

					@Override
					public void onCancel(DialogInterface dialog) {
						dialog.dismiss();
					}
				});
		return progressDialog;
	}

	/**
	 * 更新ProgressDialog提示消息
	 * 
	 * @param progressDialog
	 * @param title
	 * @param message
	 * @return
	 */
	protected ProgressDialog updataProgressDialog(String strTitle,
			String strMessage) {
		String title = "";
		String message = "";
		if (strTitle != null) {
			title = strTitle;
		}
		if (strMessage != null) {
			message = strMessage;
		}
		if (progressDialog != null && progressDialog.isShowing()) {

			progressDialog.setTitle(title);
			progressDialog.setMessage(message);
		} else {
			showProgressDialog(title, message);
		}
		return progressDialog;

	}
	
	/**
	 * 提示（长�?
	 * 
	 * @param text
	 */
	protected void showToastL(String text) {
		Toast.makeText(this, text, Toast.LENGTH_LONG).show();
	}

	/**
	 * 提示（短�?
	 * 
	 * @param text
	 */
	protected void showToastS(String text) {
		Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
	}



	/**
	 * 隐藏ProgressDialog
	 */
	protected void dismissProgressDialog() {
		if (progressDialog != null && progressDialog.isShowing()) {
			progressDialog.dismiss();
		}
	}

}
